<?=$this->form_eksternal->form_open("", 'class=" form-horizontal well ucase"', array("id_detail" => $id))?>
<div id="main-content">
  <div class="container-fluid">
    <div class="row-fluid">
			<div class="span6 ">
				<div class="nonboxy-widget">
					<div class="widget-content">
						<div class="widget-box">
								<fieldset>
									<legend id="fade_module">Privilege Module for <?=$title_form?></legend>
                  <input type="checkbox" onclick="toggleChecked(this.checked, 'privilege_module')" /> Check / Uncheck All
                  <fieldset id="privilege_module">
                    <?php
                    if(is_array($detail[0])){
                      foreach($detail[0] as $key => $dt){
//                        print_r($privilege_module[0]);
                        if($privilege_module[$key] == $dt->id_module)
                          $checklist = $this->form_eksternal->form_checkbox($dt->name, $dt->id_module, TRUE);
                        else
                          $checklist = $this->form_eksternal->form_checkbox($dt->name, $dt->id_module, FALSE);
                        print <<<EOD
                    <div class="control-group">
                      <label class="control-label">{$dt->desc}</label>
                      <div class="controls">
                        <label class="checkbox">
                            {$checklist} Access
                        </label>
                      </div>
										</div>  
EOD;
                      }
                    }
                    ?>
									</fieldset>
								</fieldset>
								<div class="form-actions">
								</div>
						</div>
					</div>
				</div>
			</div>
			<div class="span6 ">
				<div class="nonboxy-widget">
					<div class="widget-content">
						<div class="widget-box">
								<fieldset>
									<legend id="fade_menu">Privilege Menu for <?=$title_form?></legend>
                  <input type="checkbox" onclick="toggleChecked(this.checked, 'privilege_menu')" /> Check / Uncheck All
                  <fieldset id="privilege_menu">
                    <?php
                    if(is_array($detail_menu[0])){
                      foreach($detail_menu[0] as $key => $dt){
//                        print_r($privilege_module[0]);
                        if($privilege_menu[$key] == $dt->id_menu)
                          $checklist = $this->form_eksternal->form_checkbox("menu_pv[]", $dt->id_menu, TRUE);
                        else
                          $checklist = $this->form_eksternal->form_checkbox("menu_pv[]", $dt->id_menu, FALSE);
                        print <<<EOD
                    <div class="control-group">
                      <label class="control-label">{$dt->name}</label>
                      <div class="controls">
                        <label class="checkbox">
                            {$checklist} Access Self <b>{$dt->id_menu}</b> Parent {$dt->parent}
                        </label>
                      </div>
										</div>  
EOD;
                      }
                    }
                    ?>
									</fieldset>
								</fieldset>
								<div class="form-actions">
								</div>
						</div>
					</div>
				</div>
			</div>
    </div>
    <div class="row-fluid">
			<div class="span6 ">
				<div class="nonboxy-widget">
					<div class="widget-content">
						<div class="widget-box">
								<fieldset>
									<legend id="fade_page">Privilege Page for <?=$title_form?></legend>
                  <fieldset id="privilege_page">
                    <!--<pre>-->
                    <?php
//                    print_r($detail_controller[0]);die;
                    if(is_array($detail_controller[0])){
                      foreach($detail_controller[0] as $key => $dt){
                        $anak = "";
                        foreach($detail_page[$dt->id_controller] as $ky => $dp){
                          if($privilege_page[$dt->id_controller][$ky] == $dp->id_page)
                            $checklist = $this->form_eksternal->form_checkbox("page_pv[]", $dp->id_page, TRUE);
                          else
                            $checklist = $this->form_eksternal->form_checkbox("page_pv[]", $dp->id_page, FALSE);
                          $anak .= <<<EOD
                          <label class="control-label">{$dp->link}</label>
                          <div class="controls">
                            <label class="checkbox">
                                {$checklist} Access
                            </label>
                          </div>
EOD;
                        }
                        print <<<EOD
                    <div class="control-group">
                      <legend id="controller_{$dt->link}">{$dt->name}</legend>
                      <input type="checkbox" onclick="toggleChecked(this.checked, 'page_{$dt->link}')" /> Check / Uncheck All
                      <div id="page_{$dt->link}" class="control-group">
                        {$anak}
                      </div>  
										</div>  
                    <script>
                    $(document).ready(function(){
                      $("#page_{$dt->link}").hide();
                      $("#controller_{$dt->link}").click(function(){
                        $("#page_{$dt->link}").fadeToggle();
                      });
                    });
                    </script>
EOD;
                      }
                    }
                    ?>
									</fieldset>
								</fieldset>
								<div class="form-actions">
								</div>
						</div>
					</div>
				</div>
			</div>
      <div class="span6 ">
				<div class="nonboxy-widget">
					<div class="widget-content">
						<div class="widget-box">
								<fieldset>
									<legend id="fade_form">Privilege Form for <?=$title_form?></legend>
                  <input type="checkbox" onclick="toggleChecked(this.checked, 'privilege_form')" /> Check / Uncheck All
                  <fieldset id="privilege_form">
                    <?php
                    if(is_array($detail_form[0])){
                      foreach($detail_form[0] as $key => $dt){
//                        print_r($privilege_module[0]);
                        if($privilege_form[$key] == $dt->id_form){
                          $checklist = $this->form_eksternal->form_checkbox($dt->name, $dt->id_form, TRUE);
                        }
                        else{
                          $checklist = $this->form_eksternal->form_checkbox($dt->name, $dt->id_form, FALSE);
                        }
                        if($privilege_form_add[$key] == $dt->id_form){
                          $checklist_add = $this->form_eksternal->form_checkbox($dt->name."_add", $dt->id_form, TRUE);
                        }
                        else{
                          $checklist_add = $this->form_eksternal->form_checkbox($dt->name."_add", $dt->id_form, FALSE);
                        }
                        print <<<EOD
                    <div class="control-group">
                      <label class="control-label">{$dt->nicename}</label>
                      <div class="controls">
                        <label class="checkbox">
                            {$checklist} Access Edit <br>
                            {$checklist_add} Access Add
                        </label>
                      </div>
										</div>  
EOD;
                      }
                    }
                    ?>
									</fieldset>
								</fieldset>
								<div class="form-actions">
								</div>
						</div>
					</div>
				</div>
			</div>
    </div>
    <div class="row-fluid">
			<div class="span12 ">
				<div class="nonboxy-widget">
					<div class="widget-content">
						<div class="widget-box">
								<div class="form-actions">
                  <fieldset>
                    Klik title untuk menampilkan items
                  </fieldset>
									<button type="submit" class="btn btn-info">Save changes</button>
									<button class="btn btn-warning">Cancel</button>
								</div>
						</div>
					</div>
				</div>
			</div>
    </div>
  </div>
</div>
</form>
<script>
$(document).ready(function(){
  $("#privilege_menu").hide();
  $("#privilege_module").hide();
  $("#privilege_page").hide();
  $("#privilege_form").hide();
  $("#fade_menu").click(function(){
    $("#privilege_menu").fadeToggle();
  });
  $("#fade_module").click(function(){
    $("#privilege_module").fadeToggle();
  });
  $("#fade_page").click(function(){
    $("#privilege_page").fadeToggle();
  });
  $("#fade_form").click(function(){
    $("#privilege_form").fadeToggle();
  });
});
function toggleChecked(status, id) {
  $("#"+id+" input").each( function() {
    $(this).attr("checked",status);
  })
}
</script>